package code.jam.core;

import my.andoird.util.r1.AndroidArray;
import code.jam.context.JamGlossaryContext;

public class JamNoteBuffer
{
	int notebuffer[];
	int loadNoteList[];
	
	public JamNoteBuffer()
	{
		notebuffer = new int[JamGlossaryContext.NOTE_BUFFER_SIZE];
		loadNoteList = new int[JamGlossaryContext.LOAD_NOTE_LIST];
		
		AndroidArray.clear(notebuffer, 0);
		AndroidArray.clear(loadNoteList, 0);
	}
	
	public void clearNoteBuffer()
	{
		AndroidArray.clear(notebuffer, 0);
	}
	
	public int[] getNotebuffer()
	{
		return notebuffer;
	}

	public void setNotebuffer(int index, int value)
	{
		this.notebuffer[index] = value;
	}

	public int[] getLoadNoteList()
	{
		return loadNoteList;
	}

	public void setLoadNoteList(int[] loadNoteList)
	{
		this.loadNoteList = loadNoteList;
	}
	
	public int findNote(int inputNote)
	{
		int nextIndex=inputNote;
		int prevIndex=inputNote;
				
		while(true)
		{
			if(this.notebuffer[nextIndex] != 0)
			{
				return nextIndex;
			}
			if(this.notebuffer[prevIndex] != 0)
			{
				return prevIndex;
			}
			
			if(nextIndex < 35)
			{
				nextIndex++;
			}
			if (prevIndex > 0 )
			{
				prevIndex--;
			}
		}
	}
}
